package com.neu.controller;

import java.util.List;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.neu.entity.Fmeditem;
import com.neu.service.FmeditemService;
import com.neu.util.JsonResult;
import com.neu.util.ResultCode;

@RestController
@CrossOrigin
@RequestMapping("/his/fmeditem")
public class FmeditemController {

	@Autowired
	private FmeditemService fmeditemService;

	// 添加非药品收费项目

	@PostMapping(value = "/add_fmeditem")
	public JsonResult<Boolean> addFmeditem(@RequestBody String body) {

		Fmeditem fmeditem= JSON.parseObject(body,Fmeditem.class);
		boolean save = fmeditemService.addFmeditem(fmeditem);
		return new JsonResult<Boolean>(ResultCode.SUCCESS, save);
	}

	// 删除非药品收费项目 @RequestParam("id") int id
	@PostMapping("/delete_fmeditem")
	public JsonResult<Boolean> deleteFmeditem(@RequestBody String body) {
		JSONObject json = JSON.parseObject(body);
		int id= (int) json.get("id");
		boolean delete = fmeditemService.deleteFmeditem(id);
		if(delete != true) {
			return new JsonResult<Boolean>(ResultCode.ERROR,delete);
		}
		return new JsonResult<Boolean>(ResultCode.SUCCESS,delete);
	}

	// 批量删除非药品收费项目
	@PostMapping("/delete_fmeditem_more")
	public JsonResult<Boolean> delFmeditemByIds(@RequestBody Integer[] ids) {
		boolean delete = fmeditemService.delFmeditemByIds(ids);
		return new JsonResult<Boolean>(ResultCode.SUCCESS, delete);
	}

	// 修改非药品收费项目
	@PostMapping("/update_fmeditem")
	public JsonResult<Boolean> updateFmeditem(@RequestBody String body) {
		Fmeditem fmeditem= JSON.parseObject(body,Fmeditem.class);
		boolean update = fmeditemService.updateFmeditem(fmeditem);
		return new JsonResult<Boolean>(ResultCode.SUCCESS, update);
	}

	// 分页查询非药品收费项目
	@ResponseBody
	@RequestMapping("/get_fmeditem")
	public JsonResult<List<Fmeditem>> pageFmeditem(@RequestBody String body) {
		JSONObject json = JSON.parseObject(body);
		int page= (int) json.get("page");
		int limit= (int) json.get("limit");
		String  itemName= (String) json.get("itemName");
//		int recordType= (int) json.get("recordType");
		int count=fmeditemService.pageFmeditemTotal(itemName);
		List<Fmeditem> list = fmeditemService.pageFmeditem(page, limit, itemName);
		return new JsonResult<List<Fmeditem>>(ResultCode.SUCCESS, list,count);
	}
	//根据id查信息
	@ResponseBody
	@RequestMapping("/get_fmeditem_id")
	public JsonResult<List<Fmeditem>> selectById(@RequestBody String body){
		JSONObject json = JSON.parseObject(body);
		int id= (int) json.get("id");
		List<Fmeditem> list=fmeditemService.selectById(id);
		return new JsonResult<List<Fmeditem>>(ResultCode.SUCCESS,list);
	}

	//分页功能
}
